package com.fengye.i18n.hodler;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.util.StringUtils;

/**
 * @author fengyexjtu@126.com
 * @since 2024-01-25
 */

public class TenantContextHolder {
    
    private static final ThreadLocal<String> tenantHolder = new ThreadLocal<>();
    
    public static String getTenantId() {
        if (ObjectUtil.isNotNull(tenantHolder.get())) {
            String tenant = String.valueOf(tenantHolder.get());
            if (StrUtil.isNotEmpty(tenant)) {
                return tenant;
            }
            return null;
        }
        return null;
    }
    
    public static void setTenantHolder(String tenantId) {
        tenantHolder.set(tenantId);
    }
}
